﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MaximPortal.Model;
using MaximServices.Model;
using MaximServices.Services;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace maxim_portal.Controllers
{
    [EnableCors("AllowCors")]
    [Route("api/[controller]")]
    [ApiController]
    public class MottoReviewController : ControllerBase
    {
        private MottoServices _mottoServices;

        public MottoReviewController(MottoServices mottoServices)
        {
            _mottoServices = mottoServices;
        }

        // POST: api/MottoReview
        [HttpPost]
        public ResultModel<Motto> Post([FromBody]ReviewMottoModel model)
        {
            if (!ModelState.IsValid)
            {
                return BuildResult.Error(ModelState.Values.First().Errors[0].ErrorMessage, default(Motto));
            }

            Motto updateModel = new Motto
            {
                Id = model.Id,
                Modify_Time = DateTime.Now,
                TagList = model.taglist,
                Baike_Url = model.baike_Url,
            };
            try
            {
                return _mottoServices.ReviewMotto(updateModel);
            }
            catch (Exception e)
            {
                return BuildResult.Error(e.Message, updateModel);
            }
        }
    }
}
